﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GS.Config;
using GS.CMS.Entities;
using System.Data;

public partial class usercontrols_cart : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindData();
    }
    /// <summary>
    /// Lấy dữ liệu bind lên control DataList
    /// </summary>
    private void BindData()
    {
        try
        {
            if(Session[Config.SessionCart] != null)
            {
                DataTable dtCart = (DataTable)Session[Config.SessionCart];
                dtlCart.Visible = true;
                dtlCart.DataSource = dtCart;
                dtlCart.DataBind();
            }
        }
        catch (Exception ex)
        {
            TrackingError.AddTrackingError("Author: sanghv - Funtion: BindData - Usercontrol:usercontrols_cart", ex.Message);
        }
    }
    protected string LinkImage(object ImgPath, object ProductID, object CategoryID)
    {
        string html = "";
        if (ImgPath != DBNull.Value)
        {
            html += string.Format("<a href=\"product-detail.aspx?subcat0={0}&pid={1}\" ><img alt=\"\"  src=\"{2}/{3}\" style=\"border:none\" width=\"170\" /></a>",
                                   CategoryID, ProductID, Config.IamgeProduct, ImgPath);
        }
        return html;
    }
    protected string LinkHeader(object ProductID, object Name, object CategoryID)
    {
        string html = "";
        if (Name != DBNull.Value)
        {
            html += string.Format(@"<span class='title'><a href='product-detail.aspx?subcat0={0}&pid={1}' >{2}</a></span>",
                                  CategoryID, ProductID, Name);
        }
        return html;
    }
    /// <summary>
    /// Hiển thị kiểu giá
    /// </summary>
    /// <param name="Price"></param>
    /// <param name="IsMapPrice"></param>
    /// <param name="Discount"></param>
    /// <returns></returns>
    protected string Price(object Price)
    {
        string html = "";
        if (Price != DBNull.Value)
        {
            decimal price = Convert.ToDecimal(Price);
            string[] arrPrice = price.ToString("C").Split('.');
            html += string.Format("<span class='price-cart'>{0}<sup>.{1}</sup></span>", arrPrice[0], arrPrice[1]);
        }
        return html;
    }
}